package com.privated.work.exception;

import java.text.MessageFormat;

/**
 * @Description 业务异常抛出类
 * @Author JohnCoding
 * @Since 2020-12-04 10:10:28
 */
public class BusinessException extends RuntimeException {
    /**
     * 异常错误码
     */
    private String code;

    /**
     * 异常信息 该信息可以通过{0}占位符匹配下方数据
     */
    private String msg;

    /**
     * 异常需要展示的参数数组
     */
    private Object[] arguments;

    public BusinessException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BusinessException(String code, String msg, Object... arguments) {
        super(MessageFormat.format(msg, arguments));
        this.code = code;
        this.msg = MessageFormat.format(msg, arguments);
        this.arguments = arguments;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object[] getArguments() {
        return arguments;
    }

    public void setArguments(Object[] arguments) {
        this.arguments = arguments;
    }
}
